/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.ctop.modules.job.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.ctop.common.config.Global;
import com.ctop.common.persistence.Page;
import com.ctop.common.web.BaseController;
import com.ctop.common.utils.StringUtils;
import com.ctop.modules.job.entity.ScheduleJobLog;
import com.ctop.modules.job.service.ScheduleJobLogService;

/**
 * 定时任务日志Controller
 * @author linbc
 * @version 2017-12-19
 */
@Controller
@RequestMapping(value = "${adminPath}/job/scheduleJobLog")
public class ScheduleJobLogController extends BaseController {

	@Autowired
	private ScheduleJobLogService scheduleJobLogService;
	
	@ModelAttribute
	public ScheduleJobLog get(@RequestParam(required=false) String id) {
		ScheduleJobLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = scheduleJobLogService.get(id);
		}
		if (entity == null){
			entity = new ScheduleJobLog();
		}
		return entity;
	}
	
	@RequiresPermissions("job:scheduleJobLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(ScheduleJobLog scheduleJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ScheduleJobLog> page = scheduleJobLogService.findPage(new Page<ScheduleJobLog>(request, response), scheduleJobLog); 
		model.addAttribute("page", page);
		return "modules/job/scheduleJobLogList";
	}

	@RequiresPermissions("job:scheduleJobLog:view")
	@RequestMapping(value = "form")
	public String form(ScheduleJobLog scheduleJobLog, Model model) {
		model.addAttribute("scheduleJobLog", scheduleJobLog);
		return "modules/job/scheduleJobLogForm";
	}

	@RequiresPermissions("job:scheduleJobLog:edit")
	@RequestMapping(value = "save")
	public String save(ScheduleJobLog scheduleJobLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, scheduleJobLog)){
			return form(scheduleJobLog, model);
		}
		scheduleJobLogService.save(scheduleJobLog);
		addMessage(redirectAttributes, "保存定时任务日志成功");
		return "redirect:"+Global.getAdminPath()+"/job/scheduleJobLog/?repage";
	}
	
	@RequiresPermissions("job:scheduleJobLog:edit")
	@RequestMapping(value = "delete")
	public String delete(ScheduleJobLog scheduleJobLog, RedirectAttributes redirectAttributes) {
		scheduleJobLogService.delete(scheduleJobLog);
		addMessage(redirectAttributes, "删除定时任务日志成功");
		return "redirect:"+Global.getAdminPath()+"/job/scheduleJobLog/?repage";
	}

}